package org.trisoc.management.login.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;

public class LoginAction extends DispatchAction {
	public ActionForward login(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession currentSession = request.getSession(true);
		DynaActionForm loginForm = (DynaActionForm) form;
		if ("admin".equals(loginForm.get("login"))
				&& "admin".equals(loginForm.get("password"))) {			
			currentSession.setAttribute("isLogined", true);
			return mapping.findForward("listUsers");
		} else {
			currentSession.setAttribute("isLogined", false);
			return mapping.findForward("tryLogin");
		}

	}
}
